<template>
	<view>
		<uv-navbar leftText="返回" title="诊所二维码" @leftClick="backClick"></uv-navbar>
		
		
		<view class="qrcode_class">
			<view class="triangle_click" @click="qrcodeClick">
				<view class="triangle_click_code"><uv-text :text="qrcodeTypesShow?qrcodeTypesPrivately:qrcodeTypesPublicity" size="20" :bold="true" color="#fffff0"></uv-text></view>
			</view>
			
			<view class="qrcode_class_clinic">
				<view class="qrcode_class_clinic_title">
					<view class="qrcode_class_clinic_title_left">
						<view>{{ qrcodeTypesShow?qrcodeTypesPublicity.slice(0, 2):qrcodeTypesPrivately.slice(0, 2) }}版</view>
						<view>二维码</view>
					</view>
					<view class="qrcode_class_clinic_title_right">
						<uv-text :text="userinfo.clinic.clinic" size="18" :bold="true"></uv-text>
						<uv-text type="info" :text="`${userinfo.clinic.addressProvince}${userinfo.clinic.addressCity}${userinfo.clinic.addressCounty}${userinfo.clinic.address}`" size="13"></uv-text>
					</view>
				</view>
				
				<view class="qrcode_class_clinic_qr">
					<uv-qrcode ref="qrcode" :value="qrCode.value" size="550rpx" :options="qrcodeTypesShow?qrCode.options3:qrCodeNoLogo" @complete="completeQrCode"></uv-qrcode>
				</view>
				
				<uv-text type="info" block :text="qrcodeTypesShow?qrcodeTypesPublicityText:qrcodeTypesPrivatelyText" customStyle="margin-top: 30px;margin-left: auto;margin-right: auto;"></uv-text>
				<view class="qrcode_save">
					<uv-text :hairline="false" text="保存图片" :bold="true" color="#2c9c3c" customTextStyle="color: #ffffff;font-size: 28rpx"  @click="saveQrCode"></uv-text>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo: {},
				qrcodeTypes: true,
				qrcodeTypesShow: true,
				qrcodeTypesPublicity: '公开码',
				qrcodeTypesPublicityText: '扫一扫上面的二维码图案, 看处方接复诊通知',
				qrcodeTypesPrivately: '私有码',
				qrcodeTypesPrivatelyText: '扫一扫上面的二维码图案, 将成为诊所的助手',
				qrCodeGenerate: false,	// 诊所二维码是否生成完成,
				urls: 'https://fc-mp-3c6afb5c-74f9-4d68-997c-856a62f10b03.next.bspapp.com',
				qrCode: {
					value: '',
					options3: {
					useDynamicSize: true,
					// 指定二维码前景，一般可在中间放logo
					foregroundImageSrc: 'https://mp-3c6afb5c-74f9-4d68-997c-856a62f10b03.cdn.bspapp.com/QRCodeRxLogo.png'
					}
				},
				qrCodeNoLogo: { useDynamicSize: true }
			}
		},
		mounted() {
			this.userinfo = this.$store.state.userinfo
			this.toggleQrCode()
		},
		methods: {
			backClick() {
				uni.navigateBack()
			},
			toggleQrCode() {
				var params = `?clinicId=${this.userinfo.clinic._id}&`
				if (this.qrcodeTypes) {	// 公开码
					params = params + 'types1=999&types0=999&types2=2&types3=999'
				}
				if (!this.qrcodeTypes) {	// 私有码
					params = params + 'types1=1&types0=0&types2=999&types3=3'
				}
				this.qrCode.value = this.urls + params
			},
			qrcodeClick() {
				this.qrcodeTypesShow = !this.qrcodeTypesShow
				this.qrcodeTypes = !this.qrcodeTypes
				this.toggleQrCode()
			},
			completeQrCode(res) {
				this.qrCodeGenerate = res.success
			},
			saveQrCode() {
				this.toggleQrCode()
				console.log('二维码数据URL：', this.qrCode.value)
				if (this.qrCodeGenerate) {
					this.$refs.qrcode.save({
					 success: (res) => {
						uni.showToast({
							title: '已保存到系统相册',
							icon: 'success'
						})
					 }
					});
				} else {
					uni.showToast({ title: '二维码未完成', icon: 'error', duration: 2000 })
				}
			},
			
		}
	}
</script>

<style lang="scss">
	.qrcode_class {
		margin-top: 70px;
		padding: 20px 10px 20px 10px;
		
		// 三角
		.triangle_click {
			width: 0;
			height: 0;
			border-top: 60px solid #2c9c3c;
			border-right: 60px solid #2c9c3c;
			border-bottom: 60px solid transparent;
			border-left: 60px solid transparent;
			margin: 0px 0px auto auto;
			
			.triangle_click_code {
				transform: rotate(-43deg);
				margin-top: -50px;
				margin-left: 13px;
			}
		}
	
		.qrcode_class_clinic {
			
			.qrcode_class_clinic_title {
				margin-top: -5%;
				margin-left: 10%;
				display: flex;
				margin-bottom: 30px;
				
				.qrcode_class_clinic_title_left {
					width: 70px;
					font-size: 18px;
					text-align: center;
					font-weight: bold;
					background-color: #2c9c3c;
					color: #fffff0;
					border-radius: 5px;
					margin-right: 10px;
				}
				.qrcode_class_clinic_title_right {
					margin-top: 1px;
				}
			}
			
			.qrcode_class_clinic_qr {
				display: flex;
				justify-content: center;
			}
		}
		
		.qrcode_save {
		    position: fixed; /* 或者使用 position: absolute; 根据你的布局需要 */  
		    bottom: 0; /* 使其固定在底部 */  
		    left: 50%; /* 水平居中，需要配合 transform 使用 */  
		    transform: translateX(-50%); /* 水平居中 */
			margin-bottom: 30px;
		}
	
	}
	
	
</style>
